package com.tianhui.consignortwofei.mvp.ui.viewHolder.detail;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.fgs.common.widget.TabSwitchView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.OrderOperateInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailOperateInfo;
import com.tianhui.consignortwofei.mvp.ui.adapter.DetailOperateAdapter;
import com.tianhui.consignortwofei.mvp.ui.adapter.SaleCarAdapter;

import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;
import org.yczbj.ycrefreshviewlib.inter.OnItemClickListener;

/**
 * @author fgs
 * @date 2020/8/28
 * @description
 **/
public class SaleCarOperateViewHolder extends BaseViewHolder<DetailOperateInfo> {
    private FrameLayout transportTypeFrameLayout;
    private TabSwitchView mTransportTypeTabSwitchView;
    private RecyclerView operateRecyclerView;
    private DetailOperateAdapter operateAdapter;

    public SaleCarOperateViewHolder(ViewGroup parent, int res, SaleCarAdapter.OnDetailOperateItemClickListener onDetailOperateItemClickListener) {
        super(parent, res);
        transportTypeFrameLayout = getView(R.id.item_detail_operate_transportTypeFrameLayout);
        mTransportTypeTabSwitchView = getView(R.id.item_detail_operate_transportTypeTabSwitchView);

        operateRecyclerView = getView(R.id.item_detail_operate_operateRecyclerView);
        operateAdapter = new DetailOperateAdapter(getContext());
        operateRecyclerView.setAdapter(operateAdapter);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        operateRecyclerView.setLayoutManager(linearLayoutManager);
        operateAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                OrderOperateInfo detailOperateInfo = operateAdapter.getAllData().get(position);
                onDetailOperateItemClickListener.onOperateClick(position, detailOperateInfo);
            }
        });

    }

    @Override
    public void setData(DetailOperateInfo data) {
        super.setData(data);
        if (data.type == 1) { //运费计算
            operateRecyclerView.setVisibility(View.VISIBLE);
            transportTypeFrameLayout.setVisibility(View.GONE);
        } else if (data.type == 2) { //运输方式
            if (!TextUtils.isEmpty(data.operate) && data.operate.equals("1")){
                mTransportTypeTabSwitchView.setDefaultSelection(0);
            }else {
                mTransportTypeTabSwitchView.setDefaultSelection(1);
            }
            transportTypeFrameLayout.setVisibility(View.VISIBLE);
            operateRecyclerView.setVisibility(View.GONE);
        } else {
            transportTypeFrameLayout.setVisibility(View.GONE);
            operateRecyclerView.setVisibility(View.GONE);
        }
        operateAdapter.clear();
        operateAdapter.addAll(data.operateInfoList);
    }
}
